<?
	cria_variaveis($_POST,$_GET,$_FILES);
?> 
<p class="titulo" align="center"><?php echo $msg->get('DETERMINANTE_MSG_02') ?></p>
<p class="subtitulo" align="center"><?php echo $msg->get('DETERMINANTE_MSG_03') ?></font></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=determinante.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=determinante.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=determinante.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular)) {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("matriz");
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") { //leitura de dados via banco de dados - modulo de exemplos e exercicios
		include "exibe_prob_matriz_determinante_xml.php";
	}
	else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") {
	   if ((strlen($dim)==0) | ($dim<0))  { 
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=determinante.php>";
		echo $msg->get('DETERMINANTE_MSG_04');
		echo "<input type=text size='2' maxlength='2' name=dim value=".($dim).">";
		echo "<br><br>";
		echo "<input type=hidden name=executar value=sim>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
		echo "</form>"; 
		echo "<form enctype=multipart/form-data action=index.php?opcao=determinante method=post>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
		echo "</form>";
	   }
        elseif (!checaNumerico($dim))
        {
    ?>
            <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
            <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
    <?php
        }
        else  {
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=determinante.php>";
		//echo DETERMINANTE_MSG_04;
		echo "<input type=hidden name=dim value=".($dim).">";
		echo "<br><br>";
		echo "<p align=left><font face=Arial>".$msg->get('DETERMINANTE_MSG_05')."</font>";
		echo "<nobr>";
		for ($i=0; $i<$dim; $i++) {
		   echo "<br><br>";
		   for ($j=0; $j<$dim; $j++) {
				echo "<input type=text name=A[".($i)."][".($j)."] maxlength=10 size=5 value=".($A[$i][$j]).">";
		   } //end forj
		} //end fori
		echo "</nobr>";
		echo "<p>";
		echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
		echo "<br>";
		echo "</form>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=determinante.php>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
		echo "</form>";
	   } //end if
	   echo "</body>";
	}
} else {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado")
        verificaBib($xml_file);
    if (!checaNumerico($dim) || !checaNumerico($A))
    {
?>
        <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
        <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        echo "<br>";
        echo $msg->get('DETERMINANTE_MSG_04');
        //echo "<input type=text size=2 maxlength=2 name=dim value=";
        echo $dim;
        //echo " >";
        echo "<br><br>";
        echo "<p align=left><b>".$msg->get('DETERMINANTE_MSG_05')."</b> <br>";
        echo "<table border=\"0\">";
        for ($i=0; $i<$dim; $i++) {
            echo "<tr>";
            for ($j=0; $j<$dim; $j++) {
                echo "<td width=\"50\" valign=\"center\" align=\"center\">";
                echo $A[$i][$j];
                echo "</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
        echo "<br><br>";
        $det = 1;
        for ($k=0; $k<$dim-1; $k++)
        {
            for ($i=$k+1; $i<$dim; $i++)
            {
                if ($A[$k][$k]==0)
                {	// pivo se anula
                    $maior = abs($A[$k][$k]);
                    for ($cont=$k+1; $cont<$dim; $cont++)
                    {
                        if (abs($A[$cont][$k]) > $maior) {
                            $maior = abs($A[$cont][$k]);
                            $indice = $cont;
                        }
                    }
                    $troca = $indice + 1;
                    for ($l=0; $l<=$dim; $l++) { //troca de linha
                        $aux2=$A[$k][$l];
                        $A[$k][$l]=$A[$indice][$l];
                        $A[$indice][$l]=$aux2;
                    }
                    $det = -$det;
                } // end if
                $M[$i][$k]=-$A[$i][$k]/$A[$k][$k];
                for ($j=0; $j<$dim; $j++) {
                    $A[$i][$j]+=$M[$i][$k]*$A[$k][$j];
                }
            }
            echo "<br>";
            echo $k+1;
            echo "<sup>o</sup> ".$msg->get('DETERMINANTE_MSG_09')."";
            echo "<br>";
            echo "<table border=\"0\">";
            for ($cont=0; $cont<$dim; $cont++) {
                    //echo "<br>";
                echo "<tr>";
                for ($cont1=0; $cont1<$dim; $cont1++) {
                    //echo "<input type=text maxlength=10 size=5 name=A[$cont][$cont1] value=";
                    if (($dim+0)==($k+2) && $cont == $cont1)
                        echo "<td align=\"center\" valign=\"center\" width=\"50\" bgcolor=\"#FFCFAB\">";
                    else
                        echo "<td align=\"center\" valign=\"center\" width=\"50\">";
                    echo round($A[$cont][$cont1],4);
                    echo "</td>";
                        //echo ">";
                }
                if ($cont>=$k+1) {
                    echo "<td>L<sub>".($cont+1)."</sub> = L<sub>".($cont+1)."</sub> - a<sub>".($cont+1)."$cont</sub>/a<sub>$cont$cont</sub> * L<sub>$cont</sub></td>";
                }
                else echo "<td>&nbsp;</td>";
                echo "</tr>";
            }
            echo "</table>";
            echo "<br>";
        }
    
        for ($i=0; $i<$dim; $i++) {
                $det = $det * $A[$i][$i];
        }
        echo "<br>";
        echo "<b>".$msg->get('DETERMINANTE_MSG_10')."</b>";
        echo "<br>";
        echo "<br>";
        echo $msg->get('DETERMINANTE_MSG_07');
        for ($i=0; $i<$dim; $i++)
        {
            echo "A[".($i+1)."][".($i+1)."]";
            if ($i != $dim-1) 
                echo '*';
            else
                echo '=';
        }
        for ($i=0; $i<$dim; $i++)
        {
            echo $A[$i][$i];
            if ($i != $dim-1) 
                echo '*';
            else
                echo '=';
        }
        echo $det;
        echo "<p>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
        {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=determinante.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo "<br><br>".$msg->get('Outros_Exemplos')."<br>";
            $objeto  = new DomDocument();
            $objeto->load($xml_file);
            $filho = $objeto->getelementsbytagname("matrices");
            if ($filho->length > 0)
            {
                $temp = $filho->item(0)->getelementsbytagname("matrix");
                $j = 0;
                for($i = 0; $i < $temp->length; $i++)
                {
                    $conteudo = $temp->item($i)->getelementsbytagname("dim");
                    if ($conteudo->length > 0)
                    {
                        if ($j != 0) echo " | ";
                        if ($j == $indice) echo "<b>";
                        echo "<a href=\"javascript:criarLinks($j)\" title=\"Dimens&atilde;o ".$conteudo->item(0)->nodeValue."\"><u>".($j+1)."</u></a>";
                        if ($j == $indice) echo "</b>";
                        $j++;
                    }
                }
            }
        }
        echo "<br><br>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=determinante.php>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
        echo "</form>";
    }
}
?>
</div>